﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Web;

namespace _2009035.Utilities
{
    public static class Utility
    {
        public static string[] GetStringArray(Type type)
        {
            //use Reflection to get the fields in our enum
            FieldInfo[] info = type.GetFields();

            //new ArrayList to hold the values (will convert later)
            ArrayList fields = new ArrayList();

            //loop through all the fields
            foreach (FieldInfo fInfo in info)
            {
                //add each to our ArrayList
                fields.Add(fInfo.Name);
            }

            // now we convert to string array and return
            return (string[])fields.ToArray(typeof(string));
        }

        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
                return attributes[0].Description;
            else
                return value.ToString();
        }

    }
}